package com.situ.mall.controller.front;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.mall.pojo.entity.User;
import com.situ.mall.service.IUserService;
import com.situ.mall.util.JSONResult;

@Controller
@RequestMapping("/user")
public class FrontUserController {

	@ResponseBody
	@RequestMapping("/checkUserLogin.shtml")
	public JSONResult checkUserLogin(HttpSession session) {
		User user = (User) session.getAttribute("user");
		return user != null ? JSONResult.ok("已经登录") : JSONResult.error("没有登录");
	}
	
	@ResponseBody
	@RequestMapping("/login.shtml")
	public JSONResult login(String username, String password, HttpSession session) {
		if ("zhangsan".equals(username) && "123".equals(password)) {
			User user = new User();
			user.setUsername(username);
			user.setId(2);
			session.setAttribute("user", user);
			return JSONResult.ok("登录成功");
		} else {
			return JSONResult.error("登录失败");
		}
	}
}
